$(function() {

    var log = console.log;
//    log('main init');


    $(".rslides").responsiveSlides({
        auto: true, // Boolean: Animate automatically, true or false
        speed: 750, // Integer: Speed of the transition, in milliseconds
        timeout: 7000, // Integer: Time between slide transitions, in milliseconds
        pager: true, // Boolean: Show pager, true or false
        nav: false, // Boolean: Show navigation, true or false
        random: false, // Boolean: Randomize the order of the slides, true or false
        pause: false, // Boolean: Pause on hover, true or false
        pauseControls: true, // Boolean: Pause when hovering controls, true or false
        prevText: "Previous", // String: Text for the "previous" button
        nextText: "Next", // String: Text for the "next" button
        maxwidth: "726", // Integer: Max-width of the slideshow, in pixels
        navContainer: "", // Selector: Where controls should be appended to, default is after the 'ul'
        manualControls: "", // Selector: Declare custom pager navigation
        namespace: "rslides", // String: Change the default namespace used
        before: function() {
        }, // Function: Before callback
        after: function() {
        }     // Function: After callback
    });



    imagePreview = function() {
        /* CONFIG */

        xOffset = 30;
        yOffset = -30;
        doOffset = 23;

        // these 2 variable determine popup's distance from the cursor
        // you might want to adjust to get the right result

        /* END CONFIG */
        $("a.HoverImg").hover(function(e) {
            this.t = this.title;
            this.title = "";
            var c = (this.t != "") ? "<br/>" + this.t : "";
            $("body").append("<p id='preview'><img src='" + $(this).attr('data-id') + "' alt='Image preview' />" + c + "</p>");

            // Width of preview
            w = $('#preview').width();

            // Limit X to body borders
            x = ((e.pageX + xOffset + w) < $("body").innerWidth() - 10) ? e.pageX + xOffset : $("body").innerWidth() - w - doOffset;

            $("#preview").css("top", (e.pageY - yOffset) + "px").css("left", (x) + "px").fadeIn("fast");
        },
                function() {
                    this.title = this.t;
                    $("#preview").remove();
                });
        $("a.HoverImg").mousemove(function(e) {

            // Width of preview
            w = $('#preview').width();

            // Limit X to body borders
            x = ((e.pageX + xOffset + w) < $("body").innerWidth() - 20) ? e.pageX + xOffset : $("body").innerWidth() - w - doOffset;

            $("#preview").css("top", (e.pageY - yOffset) + "px").css("left", (x) + "px");
        });
    };

    imagePreview();

});